
//
//  ShopTableViewCell.m
//  afn
//
//  Created by mac on 2018/5/8.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "ShopTableViewCell.h"
#import "BarberViewController.h"
#import "ServiceDetailsViewController.h"
@implementation ShopTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(void)creatView{
    self.backgroundColor=_LightGrey;
    UIView *beijiView=[UIView new];
    [self addSubview:beijiView];
    [beijiView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.mas_equalTo(0);
        make.bottom.mas_equalTo(-7);
    }];
    beijiView.backgroundColor=[UIColor whiteColor];
    
    UILabel *shopNameLabel=[UILabel new];
    [beijiView addSubview:shopNameLabel];
    [shopNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.top.mas_equalTo(10);
    }];
    shopNameLabel.text=_model.shop_name;
    shopNameLabel.textColor=ColorWithRGB(29, 29, 29);
    shopNameLabel.font=[UIFont systemFontOfSize:16];
    
    UIScrollView *zanShiScroll=[UIScrollView new];
    [beijiView addSubview:zanShiScroll];
    [zanShiScroll mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.top.mas_equalTo(shopNameLabel.mas_bottom).mas_equalTo(10);
        make.height.mas_equalTo(80);
    }];
    zanShiScroll.scrollsToTop =NO;
    
    zanShiScroll.showsVerticalScrollIndicator = FALSE;
    zanShiScroll.showsHorizontalScrollIndicator = FALSE;
    zanShiScroll.bounces = NO;
    zanShiScroll.contentSize = CGSizeMake(_model.shop_banner.count*100+10,0);
    
    for (int i=0; i<_model.shop_banner.count; i++) {
        UIImageView *bannerImage=[UIImageView new];
        [zanShiScroll addSubview:bannerImage];
        [bannerImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(10+100*i);
            make.top.mas_equalTo(10);
            make.height.mas_equalTo(60);
            make.width.mas_equalTo(90);
        }];

        NSString *url=_model.shop_banner[i];
        [bannerImage sd_setImageWithURL:[NSURL URLWithString:url]];
    }
    if (_model.shop_service_score.doubleValue==0||_model.shop_service_score==nil) {
        UILabel *pingFenLabel=[UILabel new];
        [beijiView addSubview:pingFenLabel];
        [pingFenLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(shopNameLabel);
            make.top.mas_equalTo(zanShiScroll.mas_bottom).mas_equalTo(5);
        }];
        pingFenLabel.text=@"暂无评分";
        pingFenLabel.textColor=ColorWithRGB(149, 149, 149);
        pingFenLabel.font=[UIFont systemFontOfSize:12];
    }
    
    else{
        for (int i=0; i<_model.shop_service_score.integerValue; i++) {
            UIImageView *fenImge=[UIImageView new];
            [beijiView addSubview:fenImge];
            [fenImge mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(shopNameLabel.mas_left).mas_equalTo(20*i);
                make.height.mas_equalTo(12);
                make.width.mas_equalTo(15);
                make.top.mas_equalTo(zanShiScroll.mas_bottom).mas_equalTo(5);
            }];
            fenImge.image=[UIImage imageNamed:@"ico-zuanshi"];
        }
        
        UILabel *pingFenLabel=[UILabel new];
        [beijiView addSubview:pingFenLabel];
        [pingFenLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(shopNameLabel.mas_left).mas_equalTo(20*self->_model.shop_service_score.intValue);
            make.top.mas_equalTo(zanShiScroll.mas_bottom).mas_equalTo(5);
        }];
        pingFenLabel.text=[NSString stringWithFormat:@"%2.f分",_model.shop_service_score.floatValue];
        pingFenLabel.font=[UIFont systemFontOfSize:12];
        pingFenLabel.textColor=ColorWithRGB(149, 149, 149);
    }
    
    UILabel *timeLabel=[UILabel new];
    [beijiView addSubview:timeLabel];
    [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(shopNameLabel);
        make.top.mas_equalTo(zanShiScroll.mas_bottom).mas_equalTo(22);
    }];
    timeLabel.text=@"营业至22:00";
    timeLabel.textColor=ColorWithRGB(149, 149, 149);
    timeLabel.font=[UIFont systemFontOfSize:12];
    
    UIButton *btn=[UIButton new];
    [beijiView addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-10);
        make.centerY.mas_equalTo(timeLabel.mas_top);
        make.height.mas_equalTo(25);
        make.width.mas_equalTo(80);
    }];
    btn.backgroundColor=_backgroundColor;
    [btn setTitle:@"立即预约" forState:0];
    [btn setTitleColor:[UIColor whiteColor] forState:0];
    btn.titleLabel.font=[UIFont systemFontOfSize:13];
    btn.layer.cornerRadius=3;
    [btn addTarget:self action:@selector(yuYue:) forControlEvents:UIControlEventTouchUpInside];
    
    UIView *xianView=[UIView new];
    [beijiView addSubview:xianView];
    [xianView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.right.mas_equalTo(-10);
        make.top.mas_equalTo(timeLabel.mas_bottom).mas_equalTo(15);
        make.height.mas_equalTo(1);
    }];
    xianView.backgroundColor=_LightGrey;
    
    UIImageView *weiZhi=[UIImageView new];
    [beijiView addSubview:weiZhi];
    [weiZhi mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.top.mas_equalTo(xianView.mas_bottom).mas_equalTo(20);
        make.width.mas_equalTo(10);
        make.height.mas_equalTo(15);
    }];
    weiZhi.image=[UIImage imageNamed:@"ico-map"];
    
    UILabel *addLabel=[UILabel new];
    [beijiView addSubview:addLabel];
    [addLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(weiZhi.mas_right).mas_equalTo(6);
        make.bottom.mas_equalTo(weiZhi.mas_centerY).mas_equalTo(-3);
        make.right.mas_equalTo(-70);
    }];
    addLabel.text=_model.address;
    addLabel.textColor=ColorWithRGB(49, 49, 49);
    addLabel.font=[UIFont systemFontOfSize:12];
    
    UILabel *juLiLabel=[UILabel new];
    [beijiView addSubview:juLiLabel];
    [juLiLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(addLabel);
        make.right.mas_equalTo(addLabel);
        make.top.mas_equalTo(weiZhi.mas_centerY).mas_equalTo(3);
    }];
    juLiLabel.text=@"距离您45KM";
    juLiLabel.textColor=ColorWithRGB(49, 49, 49);
    juLiLabel.font=[UIFont systemFontOfSize:12];
    
    
    UIButton *phoneBtn=[UIButton new];
    [beijiView addSubview:phoneBtn];
    [phoneBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-10);
        make.centerY.mas_equalTo(weiZhi);
        make.width.mas_equalTo(50);
        make.height.mas_equalTo(50);
    }];
    [phoneBtn setImage:[UIImage imageNamed:@"ico-dianhua"] forState:0];
}


-(CGFloat)creatView2{
    
    self.backgroundColor=_LightGrey;
    UIView *beijiView=[UIView new];
    [self addSubview:beijiView];
    [beijiView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.mas_equalTo(0);
        make.bottom.mas_equalTo(-7);
    }];
    beijiView.backgroundColor=[UIColor whiteColor];
    
    UIImageView *tuijina=[UIImageView new];
    [beijiView addSubview:tuijina];
    [tuijina mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.top.mas_equalTo(10);
        make.width.height.mas_equalTo(20);
    }];
    tuijina.image=[UIImage imageNamed:@"ico-jian"];
    
    UILabel *tuiJinaLabel=[UILabel new];
    [beijiView addSubview:tuiJinaLabel];
    [tuiJinaLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(tuijina.mas_right).mas_equalTo(8);
        make.centerY.mas_equalTo(tuijina);
        make.right.mas_equalTo(-10);
    }];
    tuiJinaLabel.text=[NSString stringWithFormat:@"店内服务(%ld)",_fuWuArr.count];
    tuiJinaLabel.textColor=ColorWithRGB(29, 29, 29);
    tuiJinaLabel.font=[UIFont systemFontOfSize:15];
    
    if (_fuWuArr.count<=3) {
        for (int i=0; i<_model.shop_service.count; i++) {
            FuWuModel *model=[FuWuModel mj_objectWithKeyValues:_fuWuArr[i]];
            
            UIView *fuWeiView=[UIView new];
            [beijiView addSubview:fuWeiView];
            [fuWeiView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.right.mas_equalTo(0);
                make.top.mas_equalTo(tuijina.mas_bottom).mas_equalTo(15+80*i);
                make.height.mas_equalTo(80);
            }];
            fuWeiView.tag=i;
            UITapGestureRecognizer *tapGesture2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pushToSerViceView:)];
            [fuWeiView addGestureRecognizer:tapGesture2];
            
            UIImageView *imageView=[UIImageView new];
            [fuWeiView addSubview:imageView];
            [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(10);
                make.centerY.mas_equalTo(0);
                make.height.mas_equalTo(60);
                make.width.mas_equalTo(90);
            }];
            NSString *url=model.pic_url;
            [imageView sd_setImageWithURL:[NSURL URLWithString:url]];
            
            if (i!=_fuWuArr.count-1) {
                UIView *XianView=[UIView new];
                [fuWeiView addSubview:XianView];
                [XianView mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.mas_equalTo(10);
                    make.right.mas_equalTo(0);
                    make.height.mas_equalTo(1);
                    make.bottom.mas_equalTo(0);
                }];
                XianView.backgroundColor=_LightGrey;
            }
            
            UILabel *fenLeiLabel=[UILabel new];
            [fuWeiView addSubview:fenLeiLabel];
            [fenLeiLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(imageView.mas_right).mas_equalTo(10);
                make.top.mas_equalTo(imageView).mas_equalTo(2);
            }];
            fenLeiLabel.text=[NSString stringWithFormat:@"[%@]",model.hairdresser_category_name];
            fenLeiLabel.textColor=[UIColor orangeColor];
            fenLeiLabel.font=[UIFont systemFontOfSize:13];
            
            UILabel *nameLabel=[UILabel new];
            [fuWeiView addSubview:nameLabel];
            [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(fenLeiLabel.mas_right).mas_equalTo(10);
                make.right.mas_equalTo(-100);
                make.top.mas_equalTo(fenLeiLabel);
            }];
            nameLabel.text=model.hairdresser_name;
            nameLabel.textColor=ColorWithRGB(49, 49,49);
            nameLabel.font=[UIFont systemFontOfSize:13];
            nameLabel.textAlignment=NSTextAlignmentLeft;
            
            
            UIImageView *jianTouimage=[UIImageView new];
            [fuWeiView addSubview:jianTouimage];
            [jianTouimage mas_makeConstraints:^(MASConstraintMaker *make) {
                make.right.mas_equalTo(-10);
                make.centerY.mas_equalTo(0);
                make.width.mas_equalTo(6);
                make.height.mas_equalTo(9);
            }];
            jianTouimage.image=[UIImage imageNamed:@"arrow_right_black"];
            
            UILabel *payLabel=[UILabel new];
            [fuWeiView addSubview:payLabel];
            [payLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.right.mas_equalTo(jianTouimage.mas_left).mas_equalTo(-5);
                make.width.mas_equalTo(80);
                make.centerY.mas_equalTo(0);
            }];
            payLabel.textColor=ColorWithRGB(149, 149, 149);
            payLabel.text=[NSString stringWithFormat:@"已售%@",model.quantity];
            payLabel.font=[UIFont systemFontOfSize:11];
            payLabel.textAlignment=NSTextAlignmentRight;
            
            UILabel *priceLabel=[UILabel new];
            [fuWeiView addSubview:priceLabel];
            [priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(fenLeiLabel);
                make.bottom.mas_equalTo(imageView).mas_equalTo(-3);
            }];
            priceLabel.text=[NSString stringWithFormat:@"¥ %@",model.favorable_Price];
            priceLabel.textColor=_backgroundColor;
            priceLabel.font=[UIFont systemFontOfSize:16];
            
            UILabel *VIPLabel=[UILabel new];
            [fuWeiView addSubview:VIPLabel];
            [VIPLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(priceLabel.mas_right).mas_equalTo(10);
                make.centerY.mas_equalTo(priceLabel);
                make.width.mas_equalTo(25);
                make.height.mas_equalTo(15);
            }];
            VIPLabel.text=@"VIP";
            VIPLabel.font=[UIFont systemFontOfSize:12];
            VIPLabel.textColor=[UIColor whiteColor];
            VIPLabel.backgroundColor=_backgroundColor;
            VIPLabel.textAlignment=NSTextAlignmentCenter;
            CGSize size=[gongju getNSStringWeight:[NSString stringWithFormat:@"¥%@",model.sale_price] andViewWight:20 andFont:13];
            UILabel *priceLabel2=[UILabel new];
            [fuWeiView addSubview:priceLabel2];
            [priceLabel2 mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(VIPLabel.mas_right);
                make.height.top.mas_equalTo(VIPLabel);
                make.width.mas_equalTo(size.width+8);
            }];
            priceLabel2.textColor=_backgroundColor;
            priceLabel2.font=[UIFont systemFontOfSize:12];
            priceLabel2.text=[NSString stringWithFormat:@"¥%@",model.sale_price];
            priceLabel2.layer.borderColor=_backgroundColor.CGColor;
            priceLabel2.layer.borderWidth=1;
            priceLabel2.textAlignment=NSTextAlignmentCenter;
            
        }
        return 80*_fuWuArr.count+50;
    }
    else{
        
        if (_num.integerValue==1) {
            for (int i=0; i<3; i++) {
                FuWuModel *model=[FuWuModel mj_objectWithKeyValues:_fuWuArr[i]];
                
                UIView *fuWeiView=[UIView new];
                [beijiView addSubview:fuWeiView];
                [fuWeiView mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.right.mas_equalTo(0);
                    make.top.mas_equalTo(tuijina.mas_bottom).mas_equalTo(15+80*i);
                    make.height.mas_equalTo(80);
                }];
                fuWeiView.tag=i;
                UITapGestureRecognizer *tapGesture2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pushToSerViceView:)];
                [fuWeiView addGestureRecognizer:tapGesture2];
                
                UIImageView *imageView=[UIImageView new];
                [fuWeiView addSubview:imageView];
                [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.mas_equalTo(10);
                    make.centerY.mas_equalTo(0);
                    make.height.mas_equalTo(60);
                    make.width.mas_equalTo(90);
                }];
                NSString *url=model.pic_url;
                [imageView sd_setImageWithURL:[NSURL URLWithString:url]];
                
                
                UIView *XianView=[UIView new];
                [fuWeiView addSubview:XianView];
                [XianView mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.mas_equalTo(10);
                    make.right.mas_equalTo(0);
                    make.height.mas_equalTo(1);
                    make.bottom.mas_equalTo(0);
                }];
                XianView.backgroundColor=_LightGrey;
                
                
                UILabel *fenLeiLabel=[UILabel new];
                [fuWeiView addSubview:fenLeiLabel];
                [fenLeiLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.mas_equalTo(imageView.mas_right).mas_equalTo(10);
                    make.top.mas_equalTo(imageView).mas_equalTo(2);
                }];
                fenLeiLabel.text=[NSString stringWithFormat:@"[%@]",model.hairdresser_category_name];
                fenLeiLabel.textColor=[UIColor orangeColor];
                fenLeiLabel.font=[UIFont systemFontOfSize:13];
                
                UILabel *nameLabel=[UILabel new];
                [fuWeiView addSubview:nameLabel];
                [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.mas_equalTo(fenLeiLabel.mas_right).mas_equalTo(10);
                    make.right.mas_equalTo(-100);
                    make.top.mas_equalTo(fenLeiLabel);
                }];
                nameLabel.text=model.hairdresser_name;
                nameLabel.textColor=ColorWithRGB(49, 49,49);
                nameLabel.font=[UIFont systemFontOfSize:13];
                nameLabel.textAlignment=NSTextAlignmentLeft;
                
                
                UIImageView *jianTouimage=[UIImageView new];
                [fuWeiView addSubview:jianTouimage];
                [jianTouimage mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.right.mas_equalTo(-10);
                    make.centerY.mas_equalTo(0);
                    make.width.mas_equalTo(6);
                    make.height.mas_equalTo(9);
                }];
                jianTouimage.image=[UIImage imageNamed:@"arrow_right_black"];
                
                UILabel *payLabel=[UILabel new];
                [fuWeiView addSubview:payLabel];
                [payLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.right.mas_equalTo(jianTouimage.mas_left).mas_equalTo(-5);
                    make.width.mas_equalTo(80);
                    make.centerY.mas_equalTo(0);
                }];
                payLabel.textColor=ColorWithRGB(149, 149, 149);
                payLabel.text=[NSString stringWithFormat:@"已售%@",model.quantity];
                payLabel.font=[UIFont systemFontOfSize:11];
                payLabel.textAlignment=NSTextAlignmentRight;
                
                UILabel *priceLabel=[UILabel new];
                [fuWeiView addSubview:priceLabel];
                [priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.mas_equalTo(fenLeiLabel);
                    make.bottom.mas_equalTo(imageView).mas_equalTo(-3);
                }];
                priceLabel.text=[NSString stringWithFormat:@"¥ %@",model.favorable_Price];
                priceLabel.textColor=_backgroundColor;
                priceLabel.font=[UIFont systemFontOfSize:16];
                
                UILabel *VIPLabel=[UILabel new];
                [fuWeiView addSubview:VIPLabel];
                [VIPLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.mas_equalTo(priceLabel.mas_right).mas_equalTo(10);
                    make.centerY.mas_equalTo(priceLabel);
                    make.width.mas_equalTo(25);
                    make.height.mas_equalTo(15);
                }];
                VIPLabel.text=@"VIP";
                VIPLabel.font=[UIFont systemFontOfSize:12];
                VIPLabel.textColor=[UIColor whiteColor];
                VIPLabel.backgroundColor=_backgroundColor;
                VIPLabel.textAlignment=NSTextAlignmentCenter;
                CGSize size=[gongju getNSStringWeight:[NSString stringWithFormat:@"¥%@",model.sale_price] andViewWight:20 andFont:13];
                UILabel *priceLabel2=[UILabel new];
                [fuWeiView addSubview:priceLabel2];
                [priceLabel2 mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.mas_equalTo(VIPLabel.mas_right);
                    make.height.top.mas_equalTo(VIPLabel);
                    make.width.mas_equalTo(size.width+8);
                }];
                priceLabel2.textColor=_backgroundColor;
                priceLabel2.font=[UIFont systemFontOfSize:12];
                priceLabel2.text=[NSString stringWithFormat:@"¥%@",model.sale_price];
                priceLabel2.layer.borderColor=_backgroundColor.CGColor;
                priceLabel2.layer.borderWidth=1;
                priceLabel2.textAlignment=NSTextAlignmentCenter;
                
            }
            
            UIView *MoreView=[UIView new];
            [beijiView addSubview:MoreView];
            [MoreView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.right.mas_equalTo(0);
                make.bottom.mas_equalTo(0);
                make.height.mas_equalTo(50);
            }];
            MoreView.tag=2;
            UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(zhanKaiOrShouqi:)];
            [MoreView addGestureRecognizer:tapGesture];
            
            UILabel *moreLabel=[UILabel new];
            [MoreView addSubview:moreLabel];
            [moreLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.center.mas_equalTo(0);
            }];
            moreLabel.textColor=ColorWithRGB(149, 149, 149);
            moreLabel.text=[NSString stringWithFormat:@"其他(%ld)个服务",_fuWuArr.count-3];
            moreLabel.font=[UIFont systemFontOfSize:14];
            
            UIImageView *moreImage=[UIImageView new];
            [MoreView addSubview:moreImage];
            [moreImage mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(moreLabel.mas_right).mas_equalTo(3);
                make.centerY.mas_equalTo(0);
                make.width.mas_equalTo(20);
                make.height.mas_equalTo(10);
            }];
            moreImage.image=[UIImage imageNamed:@"ico-xiala"];
            
            return 340;
        }
        else{
            for (int i=0; i<_fuWuArr.count; i++) {
                FuWuModel *model=[FuWuModel mj_objectWithKeyValues:_fuWuArr[i]];
                
                UIView *fuWeiView=[UIView new];
                [beijiView addSubview:fuWeiView];
                [fuWeiView mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.right.mas_equalTo(0);
                    make.top.mas_equalTo(tuijina.mas_bottom).mas_equalTo(15+80*i);
                    make.height.mas_equalTo(80);
                }];
                fuWeiView.tag=i;
                UITapGestureRecognizer *tapGesture2 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pushToSerViceView:)];
                [fuWeiView addGestureRecognizer:tapGesture2];
                
                UIImageView *imageView=[UIImageView new];
                [fuWeiView addSubview:imageView];
                [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.mas_equalTo(10);
                    make.centerY.mas_equalTo(0);
                    make.height.mas_equalTo(60);
                    make.width.mas_equalTo(90);
                }];
                NSString *url=model.pic_url;
                [imageView sd_setImageWithURL:[NSURL URLWithString:url]];
                
                
                UIView *XianView=[UIView new];
                [fuWeiView addSubview:XianView];
                [XianView mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.mas_equalTo(10);
                    make.right.mas_equalTo(0);
                    make.height.mas_equalTo(1);
                    make.bottom.mas_equalTo(0);
                }];
                XianView.backgroundColor=_LightGrey;
                
                
                UILabel *fenLeiLabel=[UILabel new];
                [fuWeiView addSubview:fenLeiLabel];
                [fenLeiLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.mas_equalTo(imageView.mas_right).mas_equalTo(10);
                    make.top.mas_equalTo(imageView).mas_equalTo(2);
                }];
                fenLeiLabel.text=[NSString stringWithFormat:@"[%@]",model.hairdresser_category_name];
                fenLeiLabel.textColor=[UIColor orangeColor];
                fenLeiLabel.font=[UIFont systemFontOfSize:13];
                
                UILabel *nameLabel=[UILabel new];
                [fuWeiView addSubview:nameLabel];
                [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.mas_equalTo(fenLeiLabel.mas_right).mas_equalTo(10);
                    make.right.mas_equalTo(-100);
                    make.top.mas_equalTo(fenLeiLabel);
                }];
                nameLabel.text=model.hairdresser_name;
                nameLabel.textColor=ColorWithRGB(49, 49,49);
                nameLabel.font=[UIFont systemFontOfSize:13];
                nameLabel.textAlignment=NSTextAlignmentLeft;
                
                
                UIImageView *jianTouimage=[UIImageView new];
                [fuWeiView addSubview:jianTouimage];
                [jianTouimage mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.right.mas_equalTo(-10);
                    make.centerY.mas_equalTo(0);
                    make.width.mas_equalTo(6);
                    make.height.mas_equalTo(9);
                }];
                jianTouimage.image=[UIImage imageNamed:@"arrow_right_black"];
                
                UILabel *payLabel=[UILabel new];
                [fuWeiView addSubview:payLabel];
                [payLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.right.mas_equalTo(jianTouimage.mas_left).mas_equalTo(-5);
                    make.width.mas_equalTo(80);
                    make.centerY.mas_equalTo(0);
                }];
                payLabel.textColor=ColorWithRGB(149, 149, 149);
                payLabel.text=[NSString stringWithFormat:@"已售%@",model.quantity];
                payLabel.font=[UIFont systemFontOfSize:11];
                
                UILabel *priceLabel=[UILabel new];
                [fuWeiView addSubview:priceLabel];
                [priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.mas_equalTo(fenLeiLabel);
                    make.bottom.mas_equalTo(imageView).mas_equalTo(-3);
                }];
                priceLabel.text=[NSString stringWithFormat:@"¥ %@",model.favorable_Price];
                priceLabel.textColor=_backgroundColor;
                priceLabel.font=[UIFont systemFontOfSize:16];
                
                UILabel *VIPLabel=[UILabel new];
                [fuWeiView addSubview:VIPLabel];
                [VIPLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.mas_equalTo(priceLabel.mas_right).mas_equalTo(10);
                    make.centerY.mas_equalTo(priceLabel);
                    make.width.mas_equalTo(25);
                    make.height.mas_equalTo(15);
                }];
                VIPLabel.text=@"VIP";
                VIPLabel.font=[UIFont systemFontOfSize:12];
                VIPLabel.textColor=[UIColor whiteColor];
                VIPLabel.backgroundColor=_backgroundColor;
                VIPLabel.textAlignment=NSTextAlignmentCenter;
                CGSize size=[gongju getNSStringWeight:[NSString stringWithFormat:@"¥%@",model.sale_price] andViewWight:20 andFont:13];
                UILabel *priceLabel2=[UILabel new];
                [fuWeiView addSubview:priceLabel2];
                [priceLabel2 mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.mas_equalTo(VIPLabel.mas_right);
                    make.height.top.mas_equalTo(VIPLabel);
                    make.width.mas_equalTo(size.width+8);
                }];
                priceLabel2.textColor=_backgroundColor;
                priceLabel2.font=[UIFont systemFontOfSize:12];
                priceLabel2.text=[NSString stringWithFormat:@"¥%@",model.sale_price];
                priceLabel2.layer.borderColor=_backgroundColor.CGColor;
                priceLabel2.layer.borderWidth=1;
                priceLabel2.textAlignment=NSTextAlignmentCenter;
                
            }
            
            UIView *MoreView=[UIView new];
            [beijiView addSubview:MoreView];
            [MoreView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.right.mas_equalTo(0);
                make.bottom.mas_equalTo(0);
                make.height.mas_equalTo(50);
            }];
            MoreView.tag=1;
            UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(zhanKaiOrShouqi:)];
            [MoreView addGestureRecognizer:tapGesture];

            
            UILabel *moreLabel=[UILabel new];
            [MoreView addSubview:moreLabel];
            [moreLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.center.mas_equalTo(0);
            }];
            moreLabel.textColor=ColorWithRGB(149, 149, 149);
            moreLabel.text=[NSString stringWithFormat:@"收起服务"];
            moreLabel.font=[UIFont systemFontOfSize:14];
            
            UIImageView *moreImage=[UIImageView new];
            [MoreView addSubview:moreImage];
            [moreImage mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(moreLabel.mas_right).mas_equalTo(3);
                make.centerY.mas_equalTo(0);
                make.width.mas_equalTo(20);
                make.height.mas_equalTo(10);
            }];
            moreImage.image=[UIImage imageNamed:@"ico-xiala"];
            
            return 100+80*_fuWuArr.count;
        }
    }
    
    return 20;
}
-(void)creatView3{
    self.backgroundColor=_LightGrey;
    UIView *beijiView=[UIView new];
    [self addSubview:beijiView];
    [beijiView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.mas_equalTo(0);
        make.bottom.mas_equalTo(-7);
    }];
    beijiView.backgroundColor=[UIColor whiteColor];
    
    UIImageView *tuijina=[UIImageView new];
    [beijiView addSubview:tuijina];
    [tuijina mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.top.mas_equalTo(10);
        make.width.height.mas_equalTo(20);
    }];
    tuijina.image=[UIImage imageNamed:@"ico-faxingshi"];
    
    UILabel *tuiJinaLabel=[UILabel new];
    [beijiView addSubview:tuiJinaLabel];
    [tuiJinaLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(tuijina.mas_right).mas_equalTo(8);
        make.centerY.mas_equalTo(tuijina);
        make.right.mas_equalTo(-10);
    }];
    tuiJinaLabel.text=[NSString stringWithFormat:@"发型师"];
    tuiJinaLabel.textColor=ColorWithRGB(29, 29, 29);
    tuiJinaLabel.font=[UIFont systemFontOfSize:15];
    
    UIScrollView *zanShiScroll=[UIScrollView new];
    [beijiView addSubview:zanShiScroll];
    [zanShiScroll mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.right.mas_equalTo(0);
        make.top.mas_equalTo(tuijina.mas_bottom).mas_equalTo(0);
        make.height.mas_equalTo(120);
    }];
    zanShiScroll.scrollsToTop =NO;
    
    zanShiScroll.showsVerticalScrollIndicator = FALSE;
    zanShiScroll.showsHorizontalScrollIndicator = FALSE;
    zanShiScroll.bounces = NO;
    zanShiScroll.contentSize = CGSizeMake(_barBerArr.count*100+10,0);
    
    for (int i=0; i<_barBerArr.count; i++) {
        
        UIView *fasiView=[UIView new];
        [zanShiScroll addSubview:fasiView];
        [fasiView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(10+100*i);
            make.width.mas_equalTo(100);
            make.height.mas_equalTo(90);
            make.top.mas_equalTo(0);
        }];
        
        BarberModel *model=[BarberModel mj_objectWithKeyValues:_barBerArr[i]];
        UIImageView *bannerImage=[UIImageView new];
        [fasiView addSubview:bannerImage];
        [bannerImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(0);
            make.top.mas_equalTo(10);
            make.height.mas_equalTo(60);
            make.width.mas_equalTo(90);
        }];
        NSString *url=model.pic_url;
        [bannerImage sd_setImageWithURL:[NSURL URLWithString:url]];
        
        UILabel *nameLabel=[UILabel new];
        [fasiView addSubview:nameLabel];
        [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(0);
            make.top.mas_equalTo(bannerImage.mas_bottom).mas_equalTo(8);
        }];
        nameLabel.text=model.barber_name;
        nameLabel.textColor=ColorWithRGB(49, 49, 49);
        nameLabel.font=[UIFont systemFontOfSize:13];
        
        UILabel *zhiWeiLabel=[UILabel new];
        [fasiView addSubview:zhiWeiLabel];
        [zhiWeiLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.mas_equalTo(0);
            make.top.mas_equalTo(nameLabel.mas_bottom).mas_equalTo(5);
            make.width.mas_equalTo(90);
        }];
        zhiWeiLabel.textColor=ColorWithRGB(149, 149, 149);
        zhiWeiLabel.font=[UIFont systemFontOfSize:13];
        zhiWeiLabel.text=model.position;
        zhiWeiLabel.textAlignment=NSTextAlignmentCenter;
        
    }
}
-(CGFloat)creatView4{
    self.backgroundColor=_LightGrey;
    UIView *beijiView=[UIView new];
    [self addSubview:beijiView];
    [beijiView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.mas_equalTo(0);
        make.bottom.mas_equalTo(-7);
    }];
    beijiView.backgroundColor=[UIColor whiteColor];
    
    UIImageView *tuijina=[UIImageView new];
    [beijiView addSubview:tuijina];
    [tuijina mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(10);
        make.top.mas_equalTo(10);
        make.width.height.mas_equalTo(20);
    }];
    tuijina.image=[UIImage imageNamed:@"ico-fuwu"];
    
    UILabel *tuiJinaLabel=[UILabel new];
    [beijiView addSubview:tuiJinaLabel];
    [tuiJinaLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(tuijina.mas_right).mas_equalTo(8);
        make.centerY.mas_equalTo(tuijina);
        make.right.mas_equalTo(-10);
    }];
    tuiJinaLabel.text=[NSString stringWithFormat:@"商家服务"];
    tuiJinaLabel.textColor=ColorWithRGB(29, 29, 29);
    tuiJinaLabel.font=[UIFont systemFontOfSize:15];

    NSArray *nameArr = [_shop_service allKeys];
    NSMutableArray<ServiceModel *> *typeArr=[NSMutableArray arrayWithCapacity:0];
    for (int i=0; i<nameArr.count; i++) {
        [typeArr addObject:[_shop_service objectForKey:nameArr[i]]];
    }
    NSLog(@"%@",typeArr);
    
    int y=(int)typeArr.count/4;
    int x=(int)typeArr.count%4;
    if (x>0) {
        y+=1;
    }
    int index=0;
    
    for (int i=0; i<y; i++) {
        for (int j=0; j<4; j++) {
            ServiceModel *model=[ServiceModel mj_objectWithKeyValues:typeArr[index]];
            
            UIButton *btn=[UIButton new];
            [beijiView addSubview:btn];
            [btn mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(10+(_mainW-20)/4*j);
                make.width.mas_equalTo((_mainW-35)/4);
                make.top.mas_equalTo(tuijina.mas_bottom).mas_equalTo(10+40*i);
                make.height.mas_equalTo(30);
            }];
            NSString *url=model.service_url;
            [btn.imageView sd_setImageWithURL:[NSURL URLWithString:url]];
            [btn setTitle:model.service_name forState:0];
            [btn setTitleColor:[UIColor blackColor] forState:0];
            btn.titleLabel.font=[UIFont systemFontOfSize:14];
            btn.titleLabel.textAlignment=NSTextAlignmentRight;
            if (index==typeArr.count-1) {
                return 50+40*y;
            }
            index+=1;
        }
    }
    return 40;
    
    
}
-(CGFloat)creatView5{
    self.backgroundColor=_LightGrey;
    UIView *beiJingView=[UIView new];
    [self addSubview:beiJingView];
    [beiJingView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.mas_equalTo(0);
        make.bottom.mas_equalTo(-7);
    }];
    beiJingView.backgroundColor=[UIColor whiteColor];
    
    UIView *pingFenView=[UIView new];
    [beiJingView addSubview:pingFenView];
    [pingFenView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.mas_equalTo(0);
        make.height.mas_equalTo(40);
    }];
    

    if (_model.shop_service_score.doubleValue==0||_model.shop_service_score==nil) {
        UILabel *pingFenLabel=[UILabel new];
        [pingFenView addSubview:pingFenLabel];
        [pingFenLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(10);
            make.centerY.mas_equalTo(0);
        }];
        pingFenLabel.text=@"暂无评分";
        pingFenLabel.textColor=ColorWithRGB(149, 149, 149);
        pingFenLabel.font=[UIFont systemFontOfSize:12];
    }

    else{
        for (int i=0; i<_model.shop_service_score.integerValue; i++) {
            UIImageView *fenImge=[UIImageView new];
            [pingFenView addSubview:fenImge];
            [fenImge mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(10+20*i);
                make.height.mas_equalTo(12);
                make.width.mas_equalTo(15);
                make.centerY.mas_equalTo(0);
            }];
            fenImge.image=[UIImage imageNamed:@"ico-zuanshi"];
        }

        UILabel *pingFenLabel=[UILabel new];
        [pingFenView addSubview:pingFenLabel];
        [pingFenLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(20*self->_model.shop_service_score.intValue+8);
            make.centerY.mas_equalTo(0);
        }];
        pingFenLabel.text=[NSString stringWithFormat:@"%2.f分",_model.shop_service_score.floatValue];
        pingFenLabel.font=[UIFont systemFontOfSize:12];
        pingFenLabel.textColor=ColorWithRGB(149, 149, 149);
    }
    
    int index=(int)_talkArr.count;
    NSLog(@"index=%ld",_talkArr.count);
    if (index>2) {
        index=2;
    }
    int height=0;
    int height2=0;
    int height3=0;
    
    for (int i=0; i<index; i++) {
       
        TalkModel *model=[TalkModel mj_objectWithKeyValues:_talkArr[i]];
        UIView *talkView=[UIView new];
        [beiJingView addSubview:talkView];
        
        
        UIView *userView=[UIView new];
        [talkView addSubview:userView];
        [userView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.mas_equalTo(0);
            make.top.mas_equalTo(0);
            make.height.mas_equalTo(50);
        }];
        
        UIImageView *userImage=[UIImageView new];
        [userView addSubview:userImage];
        [userImage mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(10);
            make.centerY.mas_equalTo(0);
            make.width.height.mas_equalTo(40);
        }];
        userImage.layer.cornerRadius=20;
        userImage.layer.masksToBounds=YES;
        NSString *userUrl=model.image_path;
        [userImage sd_setImageWithURL:[NSURL URLWithString:userUrl]];
        userImage.backgroundColor=[UIColor redColor];
        
        UILabel *nameLabel=[UILabel new];
        [userView addSubview:nameLabel];
        [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(userImage.mas_right).mas_equalTo(5);
            make.bottom.mas_equalTo(userImage.mas_centerY).mas_equalTo(-2);
        }];
        nameLabel.text=model.nickname;
        nameLabel.textColor=ColorWithRGB(29, 29, 29);
        nameLabel.font=[UIFont systemFontOfSize:15];
        
        if (model.service_score.doubleValue==0||model.service_score==nil) {
            UILabel *pingFenLabel=[UILabel new];
            [userView addSubview:pingFenLabel];
            [pingFenLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(10);
                make.centerY.mas_equalTo(0);
            }];
            pingFenLabel.text=@"暂无评分";
            pingFenLabel.textColor=ColorWithRGB(149, 149, 149);
            pingFenLabel.font=[UIFont systemFontOfSize:12];
        }
        
        else{
            for (int i=0; i<model.service_score.integerValue; i++) {
                UIImageView *fenImge=[UIImageView new];
                [userView addSubview:fenImge];
                [fenImge mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.mas_equalTo(nameLabel).mas_equalTo(20*i);
                    make.height.mas_equalTo(12);
                    make.width.mas_equalTo(15);
                    make.top.mas_equalTo(userView.mas_centerY).mas_equalTo(3);
                }];
                fenImge.image=[UIImage imageNamed:@"ico-zuanshi"];
            }
            
        }
        UILabel *timeLabel=[UILabel new];
        [userView addSubview:timeLabel];
        [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(-10);
            make.centerY.mas_equalTo(0);
        }];
        timeLabel.textColor=ColorWithRGB(99, 99, 99);
        timeLabel.text=model.create_time;
        timeLabel.font=[UIFont systemFontOfSize:12];
        
        BaseLable *detailLabel=[BaseLable new];
        [talkView addSubview:detailLabel];
        [detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(nameLabel);
            make.right.mas_equalTo(-10);
            make.top.mas_equalTo(userView.mas_bottom).mas_equalTo(5);
        }];
        detailLabel.numberOfLines=0;
        detailLabel.text=model.evaluate_detail;
        detailLabel.textColor=ColorWithRGB(59, 59, 59);
        detailLabel.font=[UIFont systemFontOfSize:12];
        [detailLabel layoutIfNeeded];
        height=50+5+detailLabel.frame.size.height+height;
        height2=50+5+detailLabel.frame.size.height+height2;
      
        

        BOOL ismore=NO;
        if ([detailLabel needLinesWithWidth:_mainW-70]>3) {
            detailLabel.numberOfLines=3;
   
            ismore=YES;
            UIView *moreView=[UIView new];
            [talkView addSubview:moreView];
            [moreView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.right.mas_equalTo(0);
                make.top.mas_equalTo(detailLabel.mas_bottom).mas_equalTo(0);
                make.height.mas_equalTo(30);
            }];

            UILabel *moreLabel=[UILabel new];
            [moreView addSubview:moreLabel];
            [moreLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.mas_equalTo(nameLabel);
                make.centerY.mas_equalTo(0);
            }];
            moreLabel.text=@"查看更多";
            moreLabel.font=[UIFont systemFontOfSize:12];
            moreLabel.textColor=ColorWithRGB(149, 149, 149);

        };

        int y=(int)model.image_url.count/3;
        int x=(int)model.image_url.count%3;
        if (x>0) {
            y+=1;
        }
    

        if (ismore) {
            height=30+((_mainW-120)/3*0.6+10)*y+height+30;
            height2=30+((_mainW-120)/3*0.6+10)*y+height2;
        }
        else{
            height=5+((_mainW-120)/3*0.6+10)*y+height+30;
            height2=5+((_mainW-120)/3*0.6+10)*y+height2;
        }
        height2+=30;
        [talkView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(pingFenView.mas_bottom).mas_equalTo(height3);
            make.left.right.mas_equalTo(0);
            make.height.mas_equalTo(height2);
        }];
        
        UIView *XianView=[UIView new];
        [talkView addSubview:XianView];
        [XianView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.bottom.left.mas_equalTo(0);
            make.height.mas_equalTo(1);
        }];
        XianView.backgroundColor=_LightGrey;
        
        height3=height2;
        height2=0;
        
        int index2=0;
        
        for (int j=0; j<y;j++) {
            for (int k=0; k<3; k++) {
                if (index2>model.image_url.count-1) {
                    continue;
                }
                UIImageView *imgae=[UIImageView new];
                [talkView addSubview:imgae];
                [imgae mas_makeConstraints:^(MASConstraintMaker *make) {
                    make.left.mas_equalTo(nameLabel).mas_equalTo((_mainW-110)/3*k);
                    if (ismore) {
                        make.top.mas_equalTo(detailLabel.mas_bottom).mas_equalTo(30+((_mainW-120)/3*0.6+10)*j);
                    }
                    else{
                         make.top.mas_equalTo(detailLabel.mas_bottom).mas_equalTo(5+((_mainW-120)/3*0.6+10)*j);
                    }
                    make.width.mas_equalTo((_mainW-120)/3);
                    make.height.mas_equalTo((_mainW-120)/3*0.6+10);
                }];
                imgae.backgroundColor=[UIColor redColor];
                NSString *url=model.image_url[index2];
                [imgae sd_setImageWithURL:[NSURL URLWithString:url]];
                index2++;
            }

        }
    
        
    }
    return height+40;
    
}

-(IBAction)yuYue:(id)sender{
    BarberViewController *barberView=[[BarberViewController alloc] init];
    barberView.shop_id=_model.shop_id;
    [gongju pushNextViewController:self.viewController andRootController:barberView];
}


-(void)zhanKaiOrShouqi:(UITapGestureRecognizer *)tap{
    
    if (tap.view.tag==1) {
        _customSelectedBlock(@1);
    }else{
        _customSelectedBlock(@2);
    }
}
-(void)pushToSerViceView:(UITapGestureRecognizer *)tap{
    FuWuModel *model=[FuWuModel mj_objectWithKeyValues:_fuWuArr[tap.view.tag]];
    ServiceDetailsViewController *serViceView=[[ServiceDetailsViewController alloc] init];
    serViceView.hairdresser_id=model.hairdresser_id;
    [gongju pushNextViewController:self.viewController andRootController:serViceView];
    
}
-(UIImage *)imageResize :(UIImage*)img andResizeTo:(CGSize)newSize
{
    CGFloat scale = [[UIScreen mainScreen]scale];
    
    UIGraphicsBeginImageContextWithOptions(newSize, NO, scale);
    [img drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newImage;
}
@end

